Analyzing Stock Picks





Kerry Back

Overview

  • Load a model and make predictions for new data.
  • Rank stocks on predictions: best, next best, …
  • Important to interpret the model
    • What combinations of features does it like/dislike?
    • What industries does it like/dislike?

Example

  • Load model from last session
from joblib import load
forest = load("forest2.joblib")
  • Download 2022-01 data as “data” (also get SIC code).

  • Make predictions

X = data[["roeq", "mom12m"]]
data["predict"] = forest.predict(X)

Find the best stocks

Sort the stocks from best to worst

data = data.sort_values(
  by="predict",
  ascending=False
)
data = data.reset_index(drop=True)

Top 3

data.head(3)
ticker date ret roeq mom12m siccd predict
0 MAS 2022-01 -0.098120 2.117647 0.216484 3432 0.595747
1 UTL 2022-01 0.020657 0.006695 -0.032805 4931 0.591594
2 SIEN 2022-01 -0.234332 1.432579 0.033419 9999 0.590987

Bottom 3

data.tail(3)
ticker date ret roeq mom12m siccd predict
2388 ESPR 2022-01 -0.142000 0.162097 -0.664231 9999 0.127884
2389 NLS 2022-01 -0.168026 0.199621 -0.622381 7991 0.126719
2390 BWEN 2022-01 -0.058511 0.226905 -0.694830 2836 0.122231

Characteristics of best stocks

  • What is the model choosing?
  • Many different ways to try to answer this. Let’s do this:
    • Standardize characteristics as percentile ranks, so min is 0, max is 1, median is 0.5, etc.
    • Create boxplots for top stocks.
data["roeq"] = data.roeq.rank(pct=True)
data["mom12m"] = data.mom12m.rank(pct=True)

Top 3 again

data.head(3)
ticker date ret roeq mom12m siccd predict
0 MAS 2022-01 -0.098120 0.994563 0.574237 3432 0.595747
1 UTL 2022-01 0.020657 0.309494 0.291510 4931 0.591594
2 SIEN 2022-01 -0.234332 0.992472 0.368465 9999 0.590987

Bottom 3 again

data.tail(3)
ticker date ret roeq mom12m siccd predict
2388 ESPR 2022-01 -0.142000 0.932664 0.016729 9999 0.127884
2389 NLS 2022-01 -0.168026 0.944793 0.019657 7991 0.126719
2390 BWEN 2022-01 -0.058511 0.951066 0.011292 2836 0.122231

ROEQ of top 100 and bottom 100

MOM12M of top 100 and bottom 100

Industries

Industries of the top 100